using System.Collections.Generic;
using UnityEngine;
using static WaterCylinder;

/*
物品类
掉落物类为DropItem

*/


public enum ItemState{
    /// <summary>
    /// 正在被使用
    /// </summary>
    OnUse,
    /// <summary>
    /// 在容器里
    /// </summary>
    InContain,
    /// <summary>
    /// 掉落状态
    /// </summary>
    Drop,
    
}

/// <summary>
/// 物品标签
/// </summary>
public enum ItemTag{
    None,
    CanUse,
    Weapon
}

/*
物品类
*/
[CreateAssetMenu(menuName = "Item/Event")]
public class Item : ScriptableObject
{   
    /// <summary>
    /// 根据prefab创建物品
    /// </summary>
    /// <param name="prefab"></param>
    /// <returns></returns>
    public static Item Create(ScriptableObject prefab){
        return Instantiate(prefab) as Item;
    }
    
    /// <summary>
    /// 创建Resources/Items下的Item
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public static Item Create(string path){
        return Create(GetResources<ScriptableObject>("Items/" + path));
    }
    
    #region 通用物品信息

    /// <summary>
    /// 物品ID
    /// </summary>
    public int id;
    /// <summary>
    /// 物品描述
    /// </summary>
    public string info;
    /// <summary>
    /// 物品状态
    /// </summary>
    public ItemState state;
    /// <summary>
    /// 物品图像
    /// </summary>
    public Sprite sprite;
    
    /// <summary>
    /// 物品所有者
    /// </summary>
    public Entity owner;

    protected List<ItemTag> tags;
    public bool TagCheck(ItemTag t){
        return tags.Contains(t);
    }
    /// <summary>
    /// 使用事件
    /// </summary>
    [Tooltip("Event")]
    public ItemEvent useEvent;
    /// <summary>
    /// 使用时
    /// </summary>
    /// <param name="user"></param>
    public virtual void OnUse(Entity user, int arg = 0){
        useEvent?.Invoke(this);
    }
    /// <summary>
    /// 丢弃事件
    /// </summary>
    [Tooltip("Event")]
    public ItemEvent dropEvent;
    /// <summary>
    /// 丢弃时
    /// </summary>
    /// <param name="entity">丢弃该Item的Entity</param>
    public virtual void OnDrop(Entity entity){
        dropEvent?.Invoke(this);
    }
    /// <summary>
    /// 捡起事件
    /// </summary>
    [Tooltip("Event")]
    public ItemEvent pickEvent;
    /// <summary>
    /// 被拾取时
    /// </summary>
    /// <param name="entity">拾取该Item的Entity</param>
    public virtual void OnPick(Entity entity){
        pickEvent?.Invoke(this);
    }
    
    public void Use(Entity user, int arg = 0){
        OnUse(user, arg);
    }
    public void Use(){
        Use(owner);
    }

    //ScriptableObject消息
    public virtual void Reset(){
        id = 0;
        info = "";
        state = ItemState.InContain;
        tags = new List<ItemTag>();
    }
    
    #endregion

    #region 通用物品方法

    #endregion
    
}
